<script>
  import Child1 from "./Child1.svelte";
  import { setContext, getContext } from "svelte";
  setContext("key", {
    name: "default name",
    key: "default key",
  });
  //   获取不到在子组件中setContext的内容
  //   以下为错误示范
  let messageFromChild = getContext("childSetContext");
  console.log("messageFromChild", messageFromChild);
  //   下面这段代码错误：`setContext(...)` can only be used during component initialisation
  //   const setKey = () => {
  //     const detail = {
  //       name: "alm",
  //       key: "abc123",
  //     };
  //     setContext("key", detail);
  //   };
</script>

<div>
  <h1>Parent1</h1>
  <!-- <button on:click={setKey}>set key</button> -->
  <Child1 />
</div>
